September 15, 2004

Computer Languages

There are certain languages are better than others at certain tasks. However some languages are simply better than others. Here is a short explanation of what I think makes a good language.

It should be able to express everything that you want, and express it easily. If it is not Turing Complete it is not good. If it requires sublanguages to express certain common things in a simple way then there are problems with the design. If these sublanguages end up Turing Complete themselves then the design has a major problem and requires a carefull look to exise the offending part. An example of this would be static typing in object orientated languages. The main statically typed object orientated languages (c++, c#, Java) all require a Turing Complete sublanguage to get around their static typing (generics or templates), whereas the dynamically typed object orientated languages do not (SmallTalk, Objective C, and all the 'scripting' languages).

Succinct syntax:
This is not about simply the number of characters that you have to type for each intruction (if it where I would have to recomend Forth personally I would recomend amputating your hands rather than Forth), it is also about the number of syntax constructs SmallTalk can express anything with only haft a dozen syntax constructs. For example to access a data structures feilds in c, c++, and objective c you use . except if you are accessing via a pointer where you use -> pointers do not have fields, they are just simple numbers. It is obvious that you are try to access a structures fields, the complier should be able to figure that out, as it does in d, Java, and c#. Likewise in c you have to define all of your methods twice, once in the program and once in the headers. Why?

Self consistent syntax:
Once the language sets up it's rules, it should stick to them. If it needs to break them then there is obviously a problem with the rules. For example Java says no to operator overloading, except in the case of string concatination. operator overloading can caurse problems, like dynamic typing, but it is sometimes very useful, as the Java designers found to their cost.

Easy readability:
Some languages, such as Forth, are simply not human readable. Everything else can be made as readable, or unreadable as the programmer wants. This is not to say they are all the same as some will lean towards being easier to read, such as Python which was designed with this in mind, and some will lean towards being hard to read, such as Perl, which was designed so you can write it quickly with lots of short cuts.

Code reuse:
A good language lets you reuse working code that you have written before. It also lets you easily adapt that code. In object orientated languages this is often done by inhertance, you create a new object based on one you have used previously, and you should be able to replace whatever bits in the old object that you need with bits in the new object. You should not have to explicitly decide what bits of the old object might be replaced at some point in the future by things you haven't written yet, or even know that you are going to write. For example in c++ you can only override methods that are declared virtual, so if in some other future project you need to override one of the non-virtual methods you have to edit and recompile that object.
This also means that there is a pile of other peoples code orgainsed in a way that makes it easy to find the bit you need that you can reuse. Such as CPAN makes up for much of waht is wrong with Perl by minimising the amount you actually have to write.


Post a Comment

<< Home